package com.scsj.supermarket.view.activity.collectmodel;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.gigamole.navigationtabstrip.NavigationTabStrip;
import com.scsj.supermarket.R;
import com.scsj.supermarket.adapter.MainFragmentAdapter;
import com.scsj.supermarket.event.FirstEvent;
import com.scsj.supermarket.utils.RxBus;
import com.scsj.supermarket.view.activity.baseactivitymodel.BaseActivity;
import com.scsj.supermarket.view.fragment.basemodel.BaseFragment;

import java.util.ArrayList;
import java.util.List;

import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;


/**
 * 我的收藏界面
 */

public class MineCollectionActivity extends BaseActivity implements View.OnClickListener {

    private String[] titles = {"店铺", "商品"};
    private NavigationTabStrip tabStrip;
    private ViewPager mViewPager;
    private TextView topRightTv;
    private List<BaseFragment> collectFragmentsList;
    private MainFragmentAdapter mainFragmentAdapter;
    private MineCollectionFragment mineCollectionFragment1;
    private MineCollectionFragment mineCollectionFragment2;


    @Override
    protected void createView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_mine_collection);
        initData();
        initView();
        initListener();
    }

    @Override
    protected void initView() {
        topRightTv = findViewById(R.id.toolbar_title_right);
        topRightTv.setVisibility(View.VISIBLE);
        intiNavigationBar();
    }

    private void intiNavigationBar() {

        //顶部指示器
        tabStrip = findViewById(R.id.mediator_tab);
        mViewPager = findViewById(R.id.viewpager);
        mViewPager.setOffscreenPageLimit(2);

        collectFragmentsList = new ArrayList<>();

            mineCollectionFragment1 = new MineCollectionFragment(0, this);
            collectFragmentsList.add(mineCollectionFragment1);
            mineCollectionFragment2 = new MineCollectionFragment(1,this);
            collectFragmentsList.add(mineCollectionFragment2);

        mainFragmentAdapter = new MainFragmentAdapter(getSupportFragmentManager(), (ArrayList<BaseFragment>) collectFragmentsList);
        mViewPager.setAdapter(mainFragmentAdapter);
        tabStrip.setViewPager(mViewPager, 0);
        tabStrip.setTitles(titles);
        tabStrip.setStripType(NavigationTabStrip.StripType.LINE);
        tabStrip.setStripGravity(NavigationTabStrip.StripGravity.BOTTOM);
        tabStrip.setTabIndex(0, true);
    }

    @Override
    protected void initListener() {
        topRightTv.setOnClickListener(this);
    }

    @Override
    protected void initData() {

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.toolbar_title_right:
                //编辑按钮
                if (!MineCollectionFragment.isEditBtnClicked) {
                    MineCollectionFragment.isEditBtnClicked = true;
                    topRightTv.setText("取消");
                    mineCollectionFragment1.bottomLayout.setVisibility(View.VISIBLE);
                    mineCollectionFragment2.bottomLayout.setVisibility(View.VISIBLE);
                    mineCollectionFragment1.mineCollectionAdapter.setEdit(true);
                    mineCollectionFragment2.mineCollectionAdapter.setEdit(true);
                } else {
                    MineCollectionFragment.isEditBtnClicked = false;
                    topRightTv.setText("编辑");
                    mineCollectionFragment1.bottomLayout.setVisibility(View.GONE);
                    mineCollectionFragment2.bottomLayout.setVisibility(View.GONE);
                    mineCollectionFragment1.mineCollectionAdapter.setEdit(false);
                    mineCollectionFragment2.mineCollectionAdapter.setEdit(false);
                }
                break;
        }
    }
}
